package com.kc.business.service.impl;

import com.kc.business.domain.BizImageSize;
import com.kc.business.service.ImageService;
import com.kc.common.utils.ImagesUtils;
import com.kc.common.utils.JsonUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class ImageServiceImpl implements ImageService {
    /**
     * 获取图片宽高尺寸json串
     * @param imagesList
     * @return
     */
    @Override
    public String getImageSizeToJson(String[] imagesList) {
        List<String> imageList = Arrays.asList(imagesList);
        //获取图片的宽高
        List<BizImageSize> imageSizeDTOList = new ArrayList<>();
        imageList.forEach(image->{
            try {
                Map<String,Integer> map = ImagesUtils.getImgSize(image);
                imageSizeDTOList.add(new BizImageSize(image,map.get("width"),map.get("height")));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        return JsonUtils.toJson(imageSizeDTOList);
    }
}
